***************************************************
***		Do-File to plot exported results		***
***************************************************

clear
set more off
global directory = "INSERT YOUR DIRECTORY"


* manually cut and paste matrices "trend_manuf" and "trend_other" from the log file "vert_05_descript" into an empty .txt-file. *
* then read into stata: *

* Manufacturing, Mining, Utilities
import delimited "$directory\Output\trend_manuf.txt", delimiter(space, collapse) varnames(nonames) clear
	assert _N == 7
	drop v1 v3
	rename v2 year
	rename v4 leiharb100
	rename v5 seleiharb100
	rename v6 freie100
	rename v7 sefreie100
	rename v8 os_any
	rename v9 seos_any
	
* Confidence intervals 	
foreach var in leiharb100 freie100 os_any {
	gen `var'_cilb = `var' - (1.96 * se`var')
	gen `var'_ciub = `var' + (1.96 * se`var')
	}

twoway 	(line leiharb100 year, lpattern(longdash) lcolor(navy) lwidth(thick)) ///
		(rcap leiharb100_cilb leiharb100_ciub year, lcolor(navy*.6)) ///
		(line freie100 year, lpattern(shortdash) lcolor(navy) lwidth(thick)) ///
		(rcap freie100_cilb freie100_ciub year, lcolor(navy*.6)), ///
					title("Manufacturing, mining, utilities", size(large)) graphregion(color(white)) ///
/*axis labels*/		xlabel(2002(1)2008, notick labsize(medium)) xtitle("") ///
					yscale(lcolor(white)) xscale(lcolor(white)) ///
/*grid&ticks*/		ytick(0[1]6, tlcolor(white)) yscale(range(0 5)) ///
 					ylabel(0 "0%" 1"1%"  2"2%"  3"3%"  4"4%"  5"5%", labsize(large) angle(horizontal) grid glcolor(gs13) glwidth(medium)) ///
					legend(label(1 "Agency work") label(2 "") label(3 "Freelance work") label( 4 "") style(s1mono) size(medium) bmargin(medium) rows(1) region(lcolor(white))) ///
					saving(trend_manuf, replace)
					
					
* Other
import delimited "$directory\Output\trend_other.txt", delimiter(space, collapse) varnames(nonames) clear
	assert _N == 7
	drop v1 v3
	rename v2 year
	rename v4 leiharb100
	rename v5 seleiharb100
	rename v6 freie100
	rename v7 sefreie100
	rename v8 os_any
	rename v9 seos_any
	
* Confidence intervals 	
foreach var in leiharb100 freie100 os_any {
	gen `var'_cilb = `var' - (1.96 * se`var')
	gen `var'_ciub = `var' + (1.96 * se`var')
	}

twoway 	(line leiharb100 year, lpattern(longdash) lcolor(orange_red) lwidth(thick)) ///
		(rcap leiharb100_cilb leiharb100_ciub year, lcolor(orange_red*.6)) ///
		(line freie100 year, lpattern(shortdash) lcolor(orange_red) lwidth(thick)) ///
		(rcap freie100_cilb freie100_ciub year, lcolor(orange_red*.6)), ///
					title("Other industries", size(large)) graphregion(color(white)) ///
/*axis labels*/		xlabel(2002(1)2008, notick labsize(medium)) xtitle("") ///
					yscale(lcolor(white)) xscale(lcolor(white)) ///
/*grid&ticks*/		ytick(0[1]6, tlcolor(white)) yscale(range(0 5)) ///
 					ylabel(0 "0%" 1"1%"  2"2%"  3"3%"  4"4%"  5"5%", labsize(large) angle(horizontal) grid glcolor(gs13) glwidth(medium)) ///
					legend(label(1 "Agency work") label(2 "") label(3 "Freelance work") label( 4 "") style(s1mono) size(mediuim) bmargin(medium) rows(1) region(lcolor(white))) ///
					saving(trend_other, replace)
					
* Combine graphs
* manually delete one legend
graph combine trend_manuf.gph trend_other.gph, row(1) ysize(6) xsize(10) imargin(medlarge) graphregion(color(white))
		graph save Graph "$directory\Output\trend_manuf_nomanuf.gph", replace 
		erase trend_manuf.gph
		erase trend_other.gph

		
***************
*** regress ***

* manually cut and paste matrix "robustness" from the regress log file into three empty .txt-file., named "regress1" "regress2" "regress3" *
* then read into stata: *

import delimited "$directory\Output\regress1.txt", delimiter(space, collapse) varnames(nonames) clear
	assert _N == 128
	drop v1
	rename v2 modelnr
	rename v3 Npers
	rename v4 Nest
	rename v5 bleiharb10
	rename v6 seleiharb10
	rename v7 bfreie10
	rename v8 sefreie10
	rename v9 bos_panel
	save "$directory\Output\regress1.dta", replace

import delimited "$directory\Output\regress2.txt", delimiter(space, collapse) varnames(nonames) clear
	assert _N == 128
	gen float modelnr = _n
	drop v1
	rename v2 seos_panel
	rename v3 sector
	rename v4 tvctrls
	destring tvctrls, replace
	drop v5-v9
	save "$directory\Output\regress2.dta", replace
	
clear
use "$directory\Output\regress1.dta", replace
merge 1:1 modelnr using "$directory\Output\regress2.dta", nogen

label variable sector "Sector"
label define sector 1 "Manufacturing, Mining, Utilities" 2 "Other"
label value sector sector

* generate confidence intervals
foreach var in leiharb10 freie10 os_panel {
	gen `var'_cilb = b`var' - (1.96 * se`var')
	gen `var'_ciub = b`var' + (1.96 * se`var')
	}	

* format %12.8f bleiharb10 bfreie10 bos_panel
save "$directory\Output\regress.dta", replace
erase "$directory\Output\regress1.dta"
erase "$directory\Output\regress2.dta"


*** manufacturing
use "$directory\Output\regress.dta", clear
keep if sector==1

* identify min and max estimates
egen min_bleiharb10 = min(bleiharb10)
mean leiharb10_cilb if bleiharb10==min_bleiharb10
gen min_bleiharb10_cilb = _b[leiharb10_cilb]	/* confidence interval for the minumum estimate */	
mean leiharb10_ciub if bleiharb10==min_bleiharb10
gen min_bleiharb10_ciub = _b[leiharb10_ciub]	/* confidence interval for the minumum estimate */

egen max_bleiharb10 = max(bleiharb10)
mean leiharb10_cilb if bleiharb10==max_bleiharb10
gen max_bleiharb10_cilb = _b[leiharb10_cilb]	/* confidence interval for the minumum estimate */	
mean leiharb10_ciub if bleiharb10==max_bleiharb10
gen max_bleiharb10_ciub = _b[leiharb10_ciub]	/* confidence interval for the minumum estimate */

* freie
egen min_bfreie10 = min(bfreie10)
mean freie10_cilb if bfreie10==min_bfreie10
gen min_bfreie10_cilb = _b[freie10_cilb]	/* confidence interval for the minumum estimate */	
mean freie10_ciub if bfreie10==min_bfreie10
gen min_bfreie10_ciub = _b[freie10_ciub]	/* confidence interval for the minumum estimate */

egen max_bfreie10 = max(bfreie10)
mean freie10_cilb if bfreie10==max_bfreie10
gen max_bfreie10_cilb = _b[freie10_cilb]	/* confidence interval for the minumum estimate */	
mean freie10_ciub if bfreie10==max_bfreie10
gen max_bfreie10_ciub = _b[freie10_ciub]	/* confidence interval for the minumum estimate */

* os_panel
egen min_bos_panel = min(bos_panel)
mean os_panel_cilb if bos_panel==min_bos_panel
gen min_bos_panel_cilb = _b[os_panel_cilb]	/* confidence interval for the minumum estimate */	
mean os_panel_ciub if bos_panel==min_bos_panel
gen min_bos_panel_ciub = _b[os_panel_ciub]	/* confidence interval for the minumum estimate */

egen max_bos_panel = max(bos_panel)
mean os_panel_cilb if bos_panel==max_bos_panel
gen max_bos_panel_cilb = _b[os_panel_cilb]	/* confidence interval for the minumum estimate */	
mean os_panel_ciub if bos_panel==max_bos_panel
gen max_bos_panel_ciub = _b[os_panel_ciub]	/* confidence interval for the minumum estimate */

* position on xaxis [0;1]
gen min_position = 0.45
gen max_position = 0.55

keep sector min_bleiharb10-max_position
keep if _n==1
save "$directory\Output\regress_manuf.dta", replace

clear
local list "leiharb10 freie10 os_panel" 
foreach var of local list {
	
	if "`var'"=="leiharb10" {
		local name = "Agency work"
		}
	else if "`var'"=="freie10" {
		local name = "Freelance work"
		}
	else if "`var'"=="os_panel" {
		local name = "Outsourcing"
		}
	else {
		dis "error"
		}
			
	* Rents *
	use "$directory\Output\regress_manuf.dta", clear
	twoway 	(rcap		min_b`var'_cilb min_b`var'_ciub min_position,	 	msize(vtiny) lcolor(gs3) lpattern(solid)) ///
			(scatter 	min_b`var' min_position, 	msize(vlarge) mlcolor(gs3) mfcolor(navy*.6) msymbol(triangle)) ///
			(rcap		max_b`var'_cilb max_b`var'_ciub max_position,	 	msize(vtiny) lcolor(gs3) lpattern(solid)) ///
			(scatter 	max_b`var' max_position, 	msize(vlarge) mlcolor(gs3) mfcolor(navy*.6) msymbol(circle)) ///
			, legend(off) graphregion(color(white)) ///
			yline(0, lcolor(gs9) lwidth(medthick)) ///
			ylabel(-.015 "-1.5%" -.01 "-1.0%" -.005 "-0.5%" 0 "0%" .005 "+0.5%" .01 "+1.0%" .015 "+1.5%", grid notick glcolor(gs13) glwidth(medium) labsize(large) angle(horizontal)) yscale(range(-.016 .016) lwidth(medium)) ///
			yscale(lcolor(white)) xscale(lcolor(white)) ///
			xlabel(none) xscale(range(.3 .7)) xtitle(`name', size(large) margin(medium)) ///
			saving(`var'_manuf, replace)
	}

	
	
*** non-manufacturing
use "$directory\Output\regress.dta", clear
keep if sector==2 

* identify min and max estimates
egen min_bleiharb10 = min(bleiharb10)
mean leiharb10_cilb if bleiharb10==min_bleiharb10
gen min_bleiharb10_cilb = _b[leiharb10_cilb]	/* confidence interval for the minumum estimate */	
mean leiharb10_ciub if bleiharb10==min_bleiharb10
gen min_bleiharb10_ciub = _b[leiharb10_ciub]	/* confidence interval for the minumum estimate */

egen max_bleiharb10 = max(bleiharb10)
mean leiharb10_cilb if bleiharb10==max_bleiharb10
gen max_bleiharb10_cilb = _b[leiharb10_cilb]	/* confidence interval for the minumum estimate */	
mean leiharb10_ciub if bleiharb10==max_bleiharb10
gen max_bleiharb10_ciub = _b[leiharb10_ciub]	/* confidence interval for the minumum estimate */

* freie
egen min_bfreie10 = min(bfreie10)
mean freie10_cilb if bfreie10==min_bfreie10
gen min_bfreie10_cilb = _b[freie10_cilb]	/* confidence interval for the minumum estimate */	
mean freie10_ciub if bfreie10==min_bfreie10
gen min_bfreie10_ciub = _b[freie10_ciub]	/* confidence interval for the minumum estimate */

egen max_bfreie10 = max(bfreie10)
mean freie10_cilb if bfreie10==max_bfreie10
gen max_bfreie10_cilb = _b[freie10_cilb]	/* confidence interval for the minumum estimate */	
mean freie10_ciub if bfreie10==max_bfreie10
gen max_bfreie10_ciub = _b[freie10_ciub]	/* confidence interval for the minumum estimate */

* os_panel
egen min_bos_panel = min(bos_panel)
mean os_panel_cilb if bos_panel==min_bos_panel
gen min_bos_panel_cilb = _b[os_panel_cilb]	/* confidence interval for the minumum estimate */	
mean os_panel_ciub if bos_panel==min_bos_panel
gen min_bos_panel_ciub = _b[os_panel_ciub]	/* confidence interval for the minumum estimate */

egen max_bos_panel = max(bos_panel)
mean os_panel_cilb if bos_panel==max_bos_panel
gen max_bos_panel_cilb = _b[os_panel_cilb]	/* confidence interval for the minumum estimate */	
mean os_panel_ciub if bos_panel==max_bos_panel
gen max_bos_panel_ciub = _b[os_panel_ciub]	/* confidence interval for the minumum estimate */

* position on xaxis [0;1]
gen min_position = 0.45
gen max_position = 0.55

keep sector min_bleiharb10-max_position
keep if _n==1
save "$directory\Output\regress_manuf.dta", replace

clear
local list "leiharb10 freie10 os_panel" 
foreach var of local list {
	
	if "`var'"=="leiharb10" {
		local name = "Agency work"
		}
	else if "`var'"=="freie10" {
		local name = "Freelance work"
		}
	else if "`var'"=="os_panel" {
		local name = "Outsourcing"
		}
	else {
		dis "error"
		}
			
	* Rents *
	use "$directory\Output\regress_manuf.dta", clear
	twoway 	(rcap		min_b`var'_cilb min_b`var'_ciub min_position,	 	msize(vtiny) lcolor(gs3) lpattern(solid)) ///
			(scatter 	min_b`var' min_position, 	msize(vlarge) mlcolor(gs3) mfcolor(orange_red*.6) msymbol(triangle)) ///
			(rcap		max_b`var'_cilb max_b`var'_ciub max_position,	 	msize(vtiny) lcolor(gs3) lpattern(solid)) ///
			(scatter 	max_b`var' max_position, 	msize(vlarge) mlcolor(gs3) mfcolor(orange_red*.6) msymbol(circle)) ///
			, legend(off) graphregion(color(white)) ///
			yline(0, lcolor(gs9) lwidth(medthick)) ///
			ylabel(-.015 "-1.5%" -.01 "-1.0%" -.005 "-0.5%" 0 "0%" .005 "+0.5%" .01 "+1.0%" .015 "+1.5%", grid notick glcolor(gs13) glwidth(medium) labsize(large) angle(horizontal)) yscale(range(-.016 .016) lwidth(medium)) ///
			yscale(lcolor(white)) xscale(lcolor(white)) ///
			xlabel(none) xscale(range(.3 .7)) xtitle(`name', size(large) margin(medium)) ///
			saving(`var'_nomanuf, replace)
	}
	
*** Combine graphs	
*** Rents	
qui graph combine leiharb10_manuf.gph freie10_manuf.gph os_panel_manuf.gph, ///
	col(3) ysize(5) xsize(7) l1title("Capital-intensive" "industries") imargin(medsmall)	graphregion(color(white)) saving(manuf_rent_comb, replace)
	
qui graph combine leiharb10_nomanuf.gph freie10_nomanuf.gph os_panel_nomanuf.gph, ///
	col(3) ysize(5) xsize(7) l1title("Other" "industries") imargin(medsmall)	graphregion(color(white)) saving(other_rent_comb, replace)
	
graph combine manuf_rent_comb.gph other_rent_comb.gph, ///
	col(1) ysize(10) xsize(9) imargin(l=0 r=0 t=0 b=0)	graphregion(color(white)) 
	graph save "$directory\rent_combined.gph", replace
	
	
	
****************************
*** effect heterogeneity ***
****************************

import delimited "$directory\Output\regress2.txt", delimiter(space, collapse) varnames(nonames) clear
	assert _N == 128
	drop v1 v2
	gen modelnr = _n
	rename v3 sector
	rename v4 tvctrls
	rename v5 bleiharb10xbr
	rename v6 seleiharb10xbr
	rename v7 bfreie10xbr
	rename v8 sefreie10xbr
	rename v9 bos_panelxbr
	save "$directory\Output\heterogeneity1.dta", replace

import delimited "$directory\Output\regress3.txt", delimiter(space, collapse) varnames(nonames) clear
	assert _N == 128
	drop v1
	rename v2 seos_panelxbr
	rename v3 brinteract
	gen modelnr = _n
	save "$directory\Output\heterogeneity2.dta", replace
	
clear
use "$directory\Output\heterogeneity1.dta", replace
merge 1:1 modelnr using "$directory\Output\heterogeneity2.dta", nogen
order modelnr

label variable sector "Sector"
label define sector 1 "Manufacturing, Mining, Utilities" 2 "Other"
label value sector sector
destring bleiharb10xbr-seos_panelxbr, replace

* generate confidence intervals
foreach var in leiharb10xbr freie10xbr os_panelxbr {
	gen `var'_cilb = b`var' - (1.96 * se`var')
	gen `var'_ciub = b`var' + (1.96 * se`var')
	}	
	
* position on xaxis [0;1]
gen min_position = 0.43
gen max_position = 0.57

save "$directory\Output\heterogeneity.dta", replace
erase "$directory\Output\heterogeneity1.dta"
erase "$directory\Output\heterogeneity2.dta"


*** manufacturing
use "$directory\Output\heterogeneity.dta", clear
keep if sector==1 & brinteract==1

* identify min and max estimates
egen double min_bleiharb10xbr = min(bleiharb10xbr)
egen double max_bleiharb10xbr = max(bleiharb10xbr)
format bleiharb10xbr bleiharb10xbr min_bleiharb10xbr max_bleiharb10xbr %10.0g

mean leiharb10xbr_cilb if bleiharb10xbr==min_bleiharb10xbr
gen min_bleiharb10xbr_cilb = _b[leiharb10xbr_cilb]	/* confidence interval for the minumum estimate */	
mean leiharb10xbr_ciub if bleiharb10xbr==min_bleiharb10xbr
gen min_bleiharb10xbr_ciub = _b[leiharb10xbr_ciub]	/* confidence interval for the minumum estimate */

mean leiharb10xbr_cilb if bleiharb10xbr==max_bleiharb10
gen max_bleiharb10xbr_cilb = _b[leiharb10xbr_cilb]	/* confidence interval for the minumum estimate */	
mean leiharb10xbr_ciub if bleiharb10xbr==max_bleiharb10xbr
gen max_bleiharb10xbr_ciub = _b[leiharb10xbr_ciub]	/* confidence interval for the minumum estimate */

* freie
egen double min_bfreie10xbr = min(bfreie10xbr)
egen double max_bfreie10xbr = max(bfreie10xbr)
format bfreie10xbr bleiharb10xbr min_bfreie10xbr max_bleiharb10xbr %10.0g

mean freie10xbr_cilb if bfreie10xbr==min_bfreie10xbr
gen min_bfreie10xbr_cilb = _b[freie10xbr_cilb]	/* confidence interval for the minumum estimate */	
mean freie10xbr_ciub if bfreie10xbr==min_bfreie10xbr
gen min_bfreie10xbr_ciub = _b[freie10xbr_ciub]	/* confidence interval for the minumum estimate */

mean freie10xbr_cilb if bfreie10xbr==max_bfreie10xbr
gen max_bfreie10xbr_cilb = _b[freie10xbr_cilb]	/* confidence interval for the minumum estimate */	
mean freie10xbr_ciub if bfreie10xbr==max_bfreie10xbr
gen max_bfreie10xbr_ciub = _b[freie10xbr_ciub]	/* confidence interval for the minumum estimate */

* os_panel
egen double min_bos_panelxbr = min(bos_panelxbr)
egen double max_bos_panelxbr = max(bos_panelxbr)
format bos_panelxbr bleiharb10xbr min_bos_panelxbr max_bleiharb10xbr %10.0g

mean os_panelxbr_cilb if bos_panelxbr==min_bos_panelxbr
gen min_bos_panelxbr_cilb = _b[os_panelxbr_cilb]	/* confidence interval for the minumum estimate */	
mean os_panelxbr_ciub if bos_panelxbr==min_bos_panelxbr
gen min_bos_panelxbr_ciub = _b[os_panelxbr_ciub]	/* confidence interval for the minumum estimate */

mean os_panelxbr_cilb if bos_panelxbr==max_bos_panelxbr
gen max_bos_panelxbr_cilb = _b[os_panelxbr_cilb]	/* confidence interval for the minumum estimate */	
mean os_panelxbr_ciub if bos_panelxbr==max_bos_panelxbr
gen max_bos_panelxbr_ciub = _b[os_panelxbr_ciub]	/* confidence interval for the minumum estimate */

keep sector min_position max_position min_bleiharb10xbr-max_bos_panelxbr_ciub
keep if _n==1
save "$directory\Output\heterogeneity_manuf.dta", replace


clear
local list "leiharb10xbr freie10xbr os_panelxbr" 
foreach var of local list {
	
	if "`var'"=="leiharb10xbr" {
		local name = "Agency work"
		}
	else if "`var'"=="freie10xbr" {
		local name = "Freelance work"
		}
	else if "`var'"=="os_panelxbr" {
		local name = "Outsourcing"
		}
	else {
		dis "error"
		}
			
	* Effect heterogeneity *
	use "$directory\Output\heterogeneity_manuf.dta", clear
	twoway 	(rcap		min_b`var'_cilb min_b`var'_ciub min_position,	 	msize(vtiny) lcolor(gs3) lpattern(solid)) ///
			(scatter 	min_b`var' min_position, 	msize(vlarge) mlcolor(navy*.8) mlwidth(thick) mfcolor(white) msymbol(triangle)) ///
			(rcap		max_b`var'_cilb max_b`var'_ciub max_position,	 	msize(vtiny) lcolor(gs3) lpattern(solid)) ///
			(scatter 	max_b`var' max_position, 	msize(vlarge) mlcolor(navy*.8) mlwidth(thick) mfcolor(white) msymbol(circle)) ///
			, legend(off) graphregion(color(white)) ///
			yline(0, lcolor(gs9) lwidth(medthick)) ///
			ylabel(-.01 "-1.0" -.005 "-0.5" 0 "0" .005 "+0.5" .01 "+1.0" .015 "+1.5" .02 "+2.0" .025 "+2.5" .03 "+3.0", grid notick glcolor(gs13) glwidth(medium) labsize(large) angle(horizontal)) yscale(range(-.011 .031) lwidth(medium)) ///
			yscale(lcolor(white) range(-.015 .035)) xscale(lcolor(white)) ///
			xlabel(none) xscale(range(.3 .7)) xtitle(`name', size(large) margin(medium)) ///
			saving(`var'_manuf_het, replace)
	}


*** non-manufacturing
use "$directory\Output\heterogeneity.dta", clear
keep if sector==2 & brinteract==1

* identify min and max estimates
egen double min_bleiharb10xbr = min(bleiharb10xbr)
egen double max_bleiharb10xbr = max(bleiharb10xbr)
format bleiharb10xbr bleiharb10xbr min_bleiharb10xbr max_bleiharb10xbr %10.0g

mean leiharb10xbr_cilb if bleiharb10xbr==min_bleiharb10xbr
gen min_bleiharb10xbr_cilb = _b[leiharb10xbr_cilb]	/* confidence interval for the minumum estimate */	
mean leiharb10xbr_ciub if bleiharb10xbr==min_bleiharb10xbr
gen min_bleiharb10xbr_ciub = _b[leiharb10xbr_ciub]	/* confidence interval for the minumum estimate */

mean leiharb10xbr_cilb if bleiharb10xbr==max_bleiharb10
gen max_bleiharb10xbr_cilb = _b[leiharb10xbr_cilb]	/* confidence interval for the minumum estimate */	
mean leiharb10xbr_ciub if bleiharb10xbr==max_bleiharb10xbr
gen max_bleiharb10xbr_ciub = _b[leiharb10xbr_ciub]	/* confidence interval for the minumum estimate */

* freie
egen double min_bfreie10xbr = min(bfreie10xbr)
egen double max_bfreie10xbr = max(bfreie10xbr)
format bfreie10xbr bleiharb10xbr min_bfreie10xbr max_bleiharb10xbr %10.0g

mean freie10xbr_cilb if bfreie10xbr==min_bfreie10xbr
gen min_bfreie10xbr_cilb = _b[freie10xbr_cilb]	/* confidence interval for the minumum estimate */	
mean freie10xbr_ciub if bfreie10xbr==min_bfreie10xbr
gen min_bfreie10xbr_ciub = _b[freie10xbr_ciub]	/* confidence interval for the minumum estimate */

mean freie10xbr_cilb if bfreie10xbr==max_bfreie10xbr
gen max_bfreie10xbr_cilb = _b[freie10xbr_cilb]	/* confidence interval for the minumum estimate */	
mean freie10xbr_ciub if bfreie10xbr==max_bfreie10xbr
gen max_bfreie10xbr_ciub = _b[freie10xbr_ciub]	/* confidence interval for the minumum estimate */

* os_panel
egen double min_bos_panelxbr = min(bos_panelxbr)
egen double max_bos_panelxbr = max(bos_panelxbr)
format bos_panelxbr bleiharb10xbr min_bos_panelxbr max_bleiharb10xbr %10.0g

mean os_panelxbr_cilb if bos_panelxbr==min_bos_panelxbr
gen min_bos_panelxbr_cilb = _b[os_panelxbr_cilb]	/* confidence interval for the minumum estimate */	
mean os_panelxbr_ciub if bos_panelxbr==min_bos_panelxbr
gen min_bos_panelxbr_ciub = _b[os_panelxbr_ciub]	/* confidence interval for the minumum estimate */

mean os_panelxbr_cilb if bos_panelxbr==max_bos_panelxbr
gen max_bos_panelxbr_cilb = _b[os_panelxbr_cilb]	/* confidence interval for the minumum estimate */	
mean os_panelxbr_ciub if bos_panelxbr==max_bos_panelxbr
gen max_bos_panelxbr_ciub = _b[os_panelxbr_ciub]	/* confidence interval for the minumum estimate */

keep sector min_position max_position min_bleiharb10xbr-max_bos_panelxbr_ciub
keep if _n==1
save "$directory\Output\heterogeneity_other.dta", replace


clear
local list "leiharb10xbr freie10xbr os_panelxbr" 
foreach var of local list {
	
	if "`var'"=="leiharb10xbr" {
		local name = "Agency work"
		}
	else if "`var'"=="freie10xbr" {
		local name = "Freelance work"
		}
	else if "`var'"=="os_panelxbr" {
		local name = "Outsourcing"
		}
	else {
		dis "error"
		}
			
	* Rents *
	use "$directory\Output\heterogeneity_other.dta", clear
	twoway 	(rcap		min_b`var'_cilb min_b`var'_ciub min_position,	 	msize(vtiny) lcolor(gs3) lpattern(solid)) ///
			(scatter 	min_b`var' min_position, 	msize(vlarge) mlcolor(orange_red*.8) mlwidth(thick) mfcolor(white) msymbol(triangle)) ///
			(rcap		max_b`var'_cilb max_b`var'_ciub max_position,	 	msize(vtiny) lcolor(gs3) lpattern(solid)) ///
			(scatter 	max_b`var' max_position, 	msize(vlarge) mlcolor(orange_red*.8) mlwidth(thick) mfcolor(white) msymbol(circle)) ///
			, legend(off) graphregion(color(white)) ///
			yline(0, lcolor(gs9) lwidth(medthick)) ///
			ylabel(-.01 "-1.0" -.005 "-0.5" 0 "0" .005 "+0.5" .01 "+1.0" .015 "+1.5" .02 "+2.0" .025 "+2.5" .03 "+3.0", grid notick glcolor(gs13) glwidth(medium) labsize(large) angle(horizontal)) yscale(range(-.011 .031) lwidth(medium)) ///
			yscale(lcolor(white) range(-.015 .035)) xscale(lcolor(white)) ///
			xlabel(none) xscale(range(.3 .7)) xtitle(`name', size(large) margin(medium)) ///
			saving(`var'_nomanuf_het, replace)
	}

*** Combine graphs	
	
qui graph combine leiharb10xbr_manuf_het.gph freie10xbr_manuf_het.gph os_panelxbr_manuf_het.gph, ///
	col(3) ysize(5) xsize(7) l1title("Capital-intensive" "industries") imargin(medsmall)	graphregion(color(white)) saving(manuf_het_comb, replace)
	
qui graph combine leiharb10xbr_nomanuf_het.gph freie10xbr_nomanuf_het.gph os_panelxbr_nomanuf_het.gph, ///
	col(3) ysize(5) xsize(7) l1title("Other" "industries") imargin(medsmall)	graphregion(color(white)) saving(other_het_comb, replace)
	
graph combine manuf_het_comb.gph other_het_comb.gph, ///
	col(1) ysize(9) xsize(9) imargin(l=0 r=0 t=0 b=0)	graphregion(color(white)) 
	graph save "$directory\Output\het_combined.gph", replace

*** END ***
